package com.yz.lzq.liwushuo.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.drawee.view.SimpleDraweeView;
import com.yz.lzq.liwushuo.R;
import com.yz.lzq.liwushuo.bean.CategoryBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by AdminJia on 2016/11/30.
 */

public class CategorygongLAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    public CategorygongLAdapter(Context mContext, List<CategoryBean.CategoryGongLBean.DataBean
            .ChannelGroupsBean> list_gongL) {
        this.mContext = mContext;
        this.list_gongL = list_gongL;
    }

    private Context mContext = null;
    private List<CategoryBean.CategoryGongLBean.DataBean.ChannelGroupsBean> list_gongL = null;


    @Override
    public ViewHolderData onCreateViewHolder(ViewGroup parent, int viewType) {
        View veiw = LayoutInflater.from(mContext).inflate(R.layout
                .item_category_gongl_recyclerview, parent, false);


        return new ViewHolderData(veiw);
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        int id_group = 0;
        int id_1 = 0;
        int id_2 = 0;
        int id_3 = 0;
        int id_4 = 0;
        int id_5 = 0;
        int id_6 = 0;
        String name = null;

        if (holder instanceof CategorygongLAdapter.ViewHolderData) {
            CategoryBean.CategoryGongLBean.DataBean.ChannelGroupsBean channelGroupsBean = list_gongL.get
                    (position);


//            ((ViewHolderData) holder).simpleDraweeViewCategoryGongL2.setOnClickListener(this);
//            ((ViewHolderData) holder).simpleDraweeViewCategoryGongL3.setOnClickListener(this);
//            ((ViewHolderData) holder).simpleDraweeViewCategoryGongL4.setOnClickListener(this);
//            ((ViewHolderData) holder).simpleDraweeViewCategoryGongL5.setOnClickListener(this);
//            ((ViewHolderData) holder).simpleDraweeViewCategoryGongL6.setOnClickListener(this);
            List<CategoryBean.CategoryGongLBean.DataBean.ChannelGroupsBean.ChannelsBean> channels =
                    channelGroupsBean.getChannels();
            ((CategorygongLAdapter.ViewHolderData) holder).textViewCategoryGongLName.setText
                    (channelGroupsBean.getName() + "");
            id_group = channelGroupsBean.getId();
            name = channelGroupsBean.getName();

            for (int i = 0; i < 6; i++) {
                switch (i) {
                    case 0:
                        ((CategorygongLAdapter.ViewHolderData) holder)
                                .simpleDraweeViewCategoryGongL1.setImageURI(Uri.parse(channels
                                .get(i).getCover_image_url() + ""));
//                    id_1 = channels.get(i).getId();
                        id_1 = i;
                        break;
                    case 1:
                        ((CategorygongLAdapter.ViewHolderData) holder)
                                .simpleDraweeViewCategoryGongL2.setImageURI(Uri.parse(channels
                                .get(i).getCover_image_url() + ""));
                        id_2 = i;
                        break;
                    case 2:
                        ((CategorygongLAdapter.ViewHolderData) holder)
                                .simpleDraweeViewCategoryGongL3.setImageURI(Uri.parse(channels
                                .get(i).getCover_image_url() + ""));
                        id_3 = i;
                        break;
                    case 3:
                        ((CategorygongLAdapter.ViewHolderData) holder)
                                .simpleDraweeViewCategoryGongL4.setImageURI(Uri.parse(channels
                                .get(i).getCover_image_url() + ""));
                        id_4 = i;
                        break;
                    case 4:
                        ((CategorygongLAdapter.ViewHolderData) holder)
                                .simpleDraweeViewCategoryGongL5.setImageURI(Uri.parse(channels
                                .get(i).getCover_image_url() + ""));
                        id_5 = i;
                        break;
                    case 5:
                        ((CategorygongLAdapter.ViewHolderData) holder)
                                .simpleDraweeViewCategoryGongL6.setImageURI(Uri.parse(channels
                                .get(i).getCover_image_url() + ""));
                        id_6 = i;
                        break;

                }

            }
            final String finalName = name;
            final int finalId_1 = id_1;
            final int finalId_2 = id_2;
            final int finalId_3 = id_3;
            final int finalId_4 = id_4;
            final int finalId_5 = id_5;
            final int finalId_6 = id_6;
            //final int finalId_all = id_group;
            ((ViewHolderData) holder).textViewCategoryGongLAll.setOnClickListener(new View
                    .OnClickListener() {


                @Override
                public void onClick(View view) {
                    Toast.makeText(mContext, "all" + position, Toast.LENGTH_SHORT).show();
                }
            });
            ((ViewHolderData) holder).simpleDraweeViewCategoryGongL1.setOnClickListener(new View
                    .OnClickListener() {


                @Override
                public void onClick(View view) {
                    Toast.makeText(mContext, finalName + "_" + finalId_1, Toast.LENGTH_SHORT)
                            .show();
                }
            });
            ((ViewHolderData) holder).simpleDraweeViewCategoryGongL2.setOnClickListener(new View
                    .OnClickListener() {


                @Override
                public void onClick(View view) {
                    Toast.makeText(mContext, finalName + "_" + finalId_2, Toast.LENGTH_SHORT)
                            .show();
                }
            });
            ((ViewHolderData) holder).simpleDraweeViewCategoryGongL3.setOnClickListener(new View
                    .OnClickListener() {


                @Override
                public void onClick(View view) {
                    Toast.makeText(mContext, finalName + "_" + finalId_3, Toast.LENGTH_SHORT)
                            .show();
                }
            });
            ((ViewHolderData) holder).simpleDraweeViewCategoryGongL4.setOnClickListener(new View
                    .OnClickListener() {


                @Override
                public void onClick(View view) {
                    Toast.makeText(mContext, finalName + "_" + finalId_4, Toast.LENGTH_SHORT)
                            .show();
                }
            });
            ((ViewHolderData) holder).simpleDraweeViewCategoryGongL5.setOnClickListener(new View
                    .OnClickListener() {


                @Override
                public void onClick(View view) {
                    Toast.makeText(mContext, finalName + "_" + finalId_5, Toast.LENGTH_SHORT)
                            .show();
                }
            });
            ((ViewHolderData) holder).simpleDraweeViewCategoryGongL6.setOnClickListener(new View
                    .OnClickListener() {


                @Override
                public void onClick(View view) {
                    Toast.makeText(mContext, finalName + "_" + finalId_6, Toast.LENGTH_SHORT)
                            .show();
                }
            });

        }
    }

    @Override
    public int getItemCount() {
        Log.i("TAG", "=====getItemCount: " + list_gongL.size());
        return list_gongL.size();
    }

//
//    public void onClick(View view) {
//        switch (view.getId()) {
//            case R.id.textView_category_gongL_all:
//                Toast.makeText(mContext, "all", Toast.LENGTH_SHORT).show();
//                break;
////            case R.id.simpleDraweeView_category_gongL_1:
////                Toast.makeText(mContext, name + "_" + id_1, Toast.LENGTH_SHORT).show();
////                break;
//            case R.id.simpleDraweeView_category_gongL_2:
//                Toast.makeText(mContext, name + "_" + id_2, Toast.LENGTH_SHORT).show();
//                break;
//            case R.id.simpleDraweeView_category_gongL_3:
//                Toast.makeText(mContext, name + "_" + id_3, Toast.LENGTH_SHORT).show();
//                break;
//            case R.id.simpleDraweeView_category_gongL_4:
//                Toast.makeText(mContext, name + "_" + id_4, Toast.LENGTH_SHORT).show();
//                break;
//            case R.id.simpleDraweeView_category_gongL_5:
//                Toast.makeText(mContext, name + "_" + id_5, Toast.LENGTH_SHORT).show();
//                break;
//            case R.id.simpleDraweeView_category_gongL_6:
//                Toast.makeText(mContext, name + "_" + id_6, Toast.LENGTH_SHORT).show();
//                break;
//        }
//    }
//

    class ViewHolderData extends RecyclerView.ViewHolder {
        @Bind(R.id.textView_category_gongL_name)
        TextView textViewCategoryGongLName;
        @Bind(R.id.textView_category_gongL_all)
        TextView textViewCategoryGongLAll;
        @Bind(R.id.simpleDraweeView_category_gongL_1)
        SimpleDraweeView simpleDraweeViewCategoryGongL1;
        @Bind(R.id.simpleDraweeView_category_gongL_2)
        SimpleDraweeView simpleDraweeViewCategoryGongL2;
        @Bind(R.id.simpleDraweeView_category_gongL_3)
        SimpleDraweeView simpleDraweeViewCategoryGongL3;
        @Bind(R.id.simpleDraweeView_category_gongL_4)
        SimpleDraweeView simpleDraweeViewCategoryGongL4;
        @Bind(R.id.simpleDraweeView_category_gongL_5)
        SimpleDraweeView simpleDraweeViewCategoryGongL5;
        @Bind(R.id.simpleDraweeView_category_gongL_6)
        SimpleDraweeView simpleDraweeViewCategoryGongL6;

        public ViewHolderData(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

        }
    }
}
